SET NOCOUNT ON;
declare @script_name varchar(256)='CensusData_V0R00005.sql';

if exists (select 1 from dbo.database_version_information where script_name=@script_name and undone=0)
BEGIN TRY
BEGIN TRAN
	/*--Begin Code Here --*/

	if exists (select * from sys.tables where object_id=object_id('dbo.ACSSF_Load_Control'))
	drop table dbo.ACSSF_Load_Control;

	/*--End Code Here --*/
	update 
	dbo.database_version_information 
	set undone=1
	where 
	script_name=@script_name 
	and 
	undone=0;
	COMMIT TRAN;
	PRINT 'Undo Script:'+@script_name+' complete.';
END TRY
BEGIN CATCH
	declare @error_message varchar(2000);
	set @error_message='UNDO SCRIPT:'+@script_name+' FAILED! ROLLBACK!  ERROR_MESSAGE:'
	+coalesce(error_message(),'')+' ERROR_NUMBER:'+coalesce(convert(varchar(10),error_number()),'');
	ROLLBACK
	raiserror(@error_message,16,1)
END CATCH
ELSE
BEGIN
	Print 'Script:'+@script_name+' has not been executed!';
END